package com.jn.algorithm.day019.question58;

/**
 * @author 江南大学1033190417
 * @date 2022/5/10 23:18
 */
public class Solution {
    public int lengthOfLastWord(String s) {
        String[] split = s.split(" ");
        return split[split.length - 1].length();
    }

    public int lengthOfLastWord2(String s) {
        s = s.trim();
        return s.length() - 1 - s.lastIndexOf(' ');
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.lengthOfLastWord("   fly me   to   the moon  "));
    }
}
